package com.pretty.test.controller.pets.problem;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.problem.dto.ProblemPageDTO;
import com.pretty.test.controller.pets.problem.vo.ProblemPageVO;
import com.pretty.test.entity.PetsProblem;
import com.pretty.test.service.IPetsProblemService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 常见问题控制器
 * @author dujianyu
 * @since 2021-04-09
 */
@RestController
@AllArgsConstructor
@RequestMapping("/problem")
public class PetsProblemController {

    private IPetsProblemService service;

    /**
     * 自定义分页
     * @param page
     * @param dto
     */
    @GetMapping("/page")
    public R<IPage<ProblemPageVO>> page(Page<PetsProblem> page, ProblemPageDTO dto){
        return R.ok(service.selectProblemPage(page,dto));
    }

    /**
     * 自定义列表
     */
    @GetMapping("/list")
    public R<List<ProblemPageVO>> list(){
        return R.ok(service.selectProblemList());
    }

    /**
     * 新增或修改
     * @param petsMessage
     */
    @PostMapping("/submit")
    public  R<Boolean> submit(@RequestBody PetsProblem petsMessage){
        return R.ok(service.saveOrUpdate(petsMessage));
    }

    /**
     * 逻辑删除
     * @param id
     */
    @PostMapping("/delete")
    public R<Boolean> delete(String id){
        return R.ok(service.removeById(id));
    }

}
